<template>
  <div class="md-dt-topTable"> 
    <div>
      <el-form :inline="true" label-width="100" :rules="rules" ref="formInline" :model="formInline"  class="demo-form-inline">
          <el-form-item label="架次" prop="planeNo">
              <el-input class="input-width" v-model="formInline.planeNo" size="mini" placeholder="必填查询参数"></el-input>
          </el-form-item>
          <el-form-item label="AO号">
              <el-input class="input-width" v-model="formInline.aoCode" size="mini" placeholder="AO号"></el-input>
          </el-form-item>
          <el-form-item label="站位">
              <el-input class="input-width" v-model="formInline.station" size="mini" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="小车编码">
              <el-input class="input-width" v-model="formInline.carCode" size="mini" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="状态">
            <el-select size="mini" v-model="formInline.status" placeholder="是否装车">
              <el-option label="全部" value=""></el-option>
              <el-option label="已装车" value="I"></el-option>
              <el-option label="未装车" value="W"></el-option>
              <el-option label="已配送" value="S"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
              <el-button type="primary" size="mini" @click="reDatas">查询</el-button>
              <el-button type="primary" size="mini" @click="doReset">重置</el-button>
          </el-form-item>
      </el-form>
    </div>
    <div class="md-dt-firstbg">
      <el-table  ref="receiveTable"  size="mini" :data="resData" highlight-current-row @current-change="tableCurrentChange"  height="250">
        <el-table-column type="index" label="序号" width="50" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="toolCode" label="托盘编码" width="150" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="carCode" label="小车编码"  width="250" :show-overflow-tooltip="true" > </el-table-column>
        <el-table-column prop="status" label="是否装车"  width="250" :show-overflow-tooltip="true" > </el-table-column>
        <el-table-column prop="sortStatus" label="分拣状态" :show-overflow-tooltip="true"> </el-table-column>

      </el-table>
   
       <!--分页-->
      <el-pagination  @size-change="handleSizeChange"   @current-change="handleCurrentChange" :current-page="page.currentPage"
          :page-sizes="page.pageRandom" :page-size="page.pageSize" layout="total, sizes, prev, pager, next" :total="page.total">
      </el-pagination>
    </div>
    <el-row :gutter="10">
      <el-col :span="8">
        <el-table :data="list.aoInfo" size="mini">
          <el-table-column prop="aoCode" label="AO号" ></el-table-column>
          <el-table-column prop="dailyTime" label="日计划时间" ></el-table-column>
        </el-table>
      </el-col>
      <el-col :span="16">
        <el-form :inline="true" label-width="100" :model="deliveryForm"  class="demo-form-inline">
          <el-form-item label="AO号">
            <el-input class="input-width" v-model="deliveryForm.aoCode" size="mini" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="图号">
            <el-input class="input-width" v-model="deliveryForm.itemCode" size="mini" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button size="mini" type="primary" @click="doQueryMaterial">查询</el-button>
          <!-- <el-button size="mini" type="primary" @click="reSend">配送</el-button>--> 
          </el-form-item>
        </el-form>
        <el-table :data="list.matchInfo" border size="mini" @selection-change="matchInfoHandleChange">
          <el-table-column type="selection" width="50"> </el-table-column>
          <el-table-column prop="status" label="配送状态" ></el-table-column>
          <el-table-column prop="aoNo" label="AO号" width="140"></el-table-column>
          <el-table-column prop="itemCode" label="图号" width="180" show-overflow-tooltip></el-table-column>
          <el-table-column prop="qualityCode" label="质量编号" ></el-table-column>
          <el-table-column prop="isPaper" label="是否带证" :show-overflow-tooltip="true"> </el-table-column>
          <el-table-column prop="remark" label="备注" :show-overflow-tooltip="true"> </el-table-column>
          <el-table-column prop="mesCheckQualiticationId" width="180" label="合格证号" show-overflow-tooltip></el-table-column>
          <el-table-column prop="repartAss" label="装配图号" show-overflow-tooltip></el-table-column>
          <el-table-column prop="deliveryQty" label="交接数量" ></el-table-column>
          <el-table-column prop="wmsDeliveryPlanId" label="交接单主键" width="180" show-overflow-tooltip></el-table-column>
        </el-table>
      </el-col>
    </el-row>
  </div>
</template>
<script>

import { mdDtTopSearchData } from "@/utils/api.js";
import request from "@/utils/request.js";
export default {
  name: "MdDtTopTable",
  data() {
    return {
      queryParam:{},//查询参数
      page:{
          currentPage:1,
          pageSize:20,
          total:0,
          pageRandom:[50,100,500]
      },
      // 当前页数
      pageNumber: 1,
      // 数据总个数
      totalCount: 0,
      // 返回的数据数组
      resData: [],
      currentRow:{},
      // 每页数据个数
      pageSize: 20,
      // 确认列表高亮参数
      stableIndex: 0,
      rules:{
        planeNo:[{ required: true, message: '请输入架次', trigger: 'blur' }]
      },
      formInline:{
        planeNo:"",
        station:"",
        carCode:"",
        aoCode:"",
        status:""
      },
      deliveryForm:{
        aoCode:"",
        itemCode:""
      },
      list:{
        aoInfo:[],
        matchInfo:[],
        selectData:[]
      }
    };
  },
  methods: {
    // 每页数据变化
    handleSizeChange(val) {
      this.pageSize = val;
      mdDtTopSearchData({
        page: {
          pageSize: this.pageSize,
          currentPage: this.pageNumber,
        },
        queryParam:this.formInline
      }).then((res) => {
        this.page.total = res.data.total;
        this.resData = res.data.list;
          console.log('配送任务Top表',res)
      });
    },
    // 分页
    handleCurrentChange(val) {
      this.pageNumber = val;
      mdDtTopSearchData({
        page: {
          pageSize: this.pageSize,
          currentPage: this.pageNumber,
        },
        queryParam:this.formInline
      }).then((res) => {
        this.page.total = res.data.total;
        this.resData = res.data.list;
          console.log('配送任务Top表',res)
      });
    },
     // 单选表格函数
    tableCurrentChange(val) {
        this.currentRow = val;
        this.$options.methods.handleClick.bind(this)(val);
    },
    matchInfoHandleChange(val){
        this.list.selectData = val;
    },
    reDatas(){
      this.$refs["formInline"].validate((valid) => {
          if (valid) {
            mdDtTopSearchData({
                queryParam:this.formInline,
                page: {
                  pageSize: this.pageSize,
                  currentPage: this.pageNumber,
                },
                queryParam:this.formInline
            }).then((res) => {
              this.page.total = res.data.total;
              this.resData = res.data.list;
            });
          } else {
            console.log('error submit!!');
            return false;
          }
      });
      
    },
    doReset(){
        Object.assign(this.formInline,this.$options.data().formInline);
    },
    handleClick(row){
      request.post("/MsDeliveryPackageInfoRest/queryNoDaliyTimeAoByCarCode",row).then((res)=>{
        this.list.aoInfo = res.data;
      });
      request.post("/MsDeliveryPackageInfoRest/querySendMaterial",row).then((res)=>{
        this.list.matchInfo = res.data;
      });
    },
    doQueryMaterial(){
      this.currentRow.aoCode = this.deliveryForm.aoCode;
      this.currentRow.itemCode = this.deliveryForm.itemCode;
      request.post("/MsDeliveryPackageInfoRest/querySendMaterial",this.currentRow).then((res)=>{
        this.list.matchInfo = res.data;
      });
    },
    reSend(){//配送
      if(this.list.selectData.length==0){
        this.$Alert({title:"错误",type:"error",message:"请至少选择一条数据"});
        return;
      }
      request.post("/MsDeliveryPackageInfoRest/deliveryPackageSingle",this.list.selectData).then((res)=>{
        console.log("=============",res);
        if(res.data.retCode=="200"){
          this.$Alert({title:"成功",type:"success",message:res.data.message});
        }else{
          this.$Alert({title:"错误",type:"error",message:res.data.message});
        }
        this.$options.methods.doQueryMaterial.bind(this)();
      })
    }
  },
  mounted() {
    // 配送后 刷新
    this.$bus.$on('mdDtPsSx',(e)=>{
      mdDtTopSearchData({
        queryParam:{},
            page: {
              pageSize: this.pageSize,
              currentPage: this.pageNumber,
            },
            queryParam:this.formInline
        }).then((res) => {
          this.page.total = res.data.total;
          this.resData = res.data.list;
            console.log('配送任务Top表',res)
        });
    })
    mdDtTopSearchData({
      queryParam:{},
        page: {
          pageSize: this.pageSize,
          currentPage: this.pageNumber,
        },
        queryParam:this.formInline
      }).then((res) => {
        this.page.total = res.data.total;
        this.resData = res.data.list;
          console.log('配送任务Top表',res)
      });
  },
};
</script>
<style scoped>

</style>